#include "Actions/ActionMoveCamera.h"

using namespace Ogre;
ActionMoveCamera::ActionMoveCamera(Ogre::Camera *mCam)
{
	mCamera = mCam;
    mCamNode = mCamera->getParentSceneNode();
	mDirection = Vector3::ZERO;
    mMove = 250;
    mRotate = 0.13;
}

ActionMoveCamera::~ActionMoveCamera(){}

void ActionMoveCamera::updateGraphics(const FrameEvent &evt){

	mCamera->getParentNode()->translate(mDirection * evt.timeSinceLastFrame, Node::TS_LOCAL);
	
}

void ActionMoveCamera::mouseMoved(const OIS::MouseEvent &evt){

	mCamNode->yaw(Degree(-mRotate * evt.state.X.rel), Node::TS_WORLD);
	mCamNode->pitch(Degree(-mRotate * evt.state.Y.rel), Node::TS_LOCAL);
}

void ActionMoveCamera::keyPressed(const OIS::KeyEvent &evt){
	
	switch (evt.key)
	{
		case OIS::KC_UP:
		case OIS::KC_W:
			moveFw();
			break;

		case OIS::KC_DOWN:
		case OIS::KC_S:
			moveBk();
			break;

		case OIS::KC_LEFT:
		case OIS::KC_A:
			moveLeft();
			break;

		case OIS::KC_RIGHT:
		case OIS::KC_D:
			moveRight();
			break;

		case OIS::KC_PGDOWN:
		case OIS::KC_E:
			moveDown();
			break;

		case OIS::KC_PGUP:
		case OIS::KC_Q:
			moveUp();
			break;

	}
}
void ActionMoveCamera::keyReleased(const OIS::KeyEvent &e){

	switch (e.key)
	{
		case OIS::KC_UP:
		case OIS::KC_W:
			stopFw();
			break;

		case OIS::KC_DOWN:
		case OIS::KC_S:
			stopBk();
			break;

		case OIS::KC_LEFT:
		case OIS::KC_A:
			stopLeft();
			break;

		case OIS::KC_RIGHT:
		case OIS::KC_D:
			stopRight();
			break;

		case OIS::KC_PGDOWN:
		case OIS::KC_E:
			stopDown();
			break;

		case OIS::KC_PGUP:
		case OIS::KC_Q:
			stopUp();
			break;
	}
}

void ActionMoveCamera::moveFw(){
	mDirection.z = -mMove;
}

void ActionMoveCamera::moveBk(){
	mDirection.z = mMove;
}

void ActionMoveCamera::moveLeft(){
	mDirection.x = -mMove;
}

void ActionMoveCamera::moveRight(){
	mDirection.x = mMove;
}

void ActionMoveCamera::moveDown(){
	mDirection.y = -mMove;
}

void ActionMoveCamera::moveUp(){
	mDirection.y = mMove;
}

void ActionMoveCamera::stopFw(){
	mDirection.z = 0;
}

void ActionMoveCamera::stopBk(){
	mDirection.z = 0;
}

void ActionMoveCamera::stopLeft(){
	mDirection.x = 0;
}

void ActionMoveCamera::stopRight(){
	mDirection.x = 0;
}

void ActionMoveCamera::stopDown(){
	mDirection.y = 0;
}

void ActionMoveCamera::stopUp(){
	mDirection.y = 0;
}